/*
Copyright 2025 PerfXLab (Beijing) Technologies Co., Ltd.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "OpenSparseBLAS_func.h"
#include "OpenSparseBLAS_type.h"

#ifdef __cplusplus
extern "C" {
#endif
    void OpenSpB_Global_is_csc_set(bool is_csc);
    bool OpenSpB_Global_is_csc_get();

    OpenSpB_vector_format_value_ext OpenSpB_Global_get_Vector_Format();
    void OpenSpB_Global_Vector_Format_set(OpenSpB_vector_format_value_ext format);

    // Linked list Node structure.
    typedef struct listNode_struct
    {
        struct listNode_struct *next;
        OpenSpB_index data;
    } listNode;

    /** This structure record some messages used in SpVSpM
     * @param Indices_NZRows : Indices of the non-zero rows of the matrix selected by the input vector. @capacity_vector_nnz elements should be allocated to it.
     * @param LL_Index_Ptr : The indices of all selected non-zero rows in @ListNodes, which is similar to the ptr array in CSC or CSR format. (@capacity_vector_nnz + 1) elements should be  allocated to it.
     * @param ListNodes : The array which stores all the linked list generated by all non-zero rows/cols. @capacity_nnz elements should be allocated to it.
     * @param ListPtr : Array of pointers to all linked tables, which corresponds to LL_Index_Ptr. @capacity_nnz_row elements should be allocated to it.
     */
    typedef struct
    {
        unsigned int capacity_vector_nnz;
        unsigned int capacity_nnz;
        unsigned int capacity_nnz_row;

        unsigned int *Indices_NZRows;
        unsigned int *LL_Index_Ptr;
        listNode *ListNodes;
        listNode **ListPtr;
    } LinkedListMes_t;

    extern LinkedListMes_t LinkedListMes;

    /**These functions are about memory management for the temporary arrays used in vxm.
     * They will control and utilize the above LinkedListMes.
     * ! Currently, these functions are only used in SpVCSRM_LOR_LAND_SEMIRING_BOOL_LinkTable
     */
    void OpenSpB_LinkedList_malloc();
    void OpenSpB_LinkedList_grow(unsigned int nnz, unsigned int nnz_row);
    void OpenSpB_LinkedList_free();
    void OpenSpB_NNZ_Counting_Mes_malloc();
    void OpenSpB_NNZ_Counting_Mes_grow(unsigned int nnz);
    void OpenSpB_NNZ_Counting_Mes_free();

    bool OpenSpB_Warning_switch_get();
#ifdef __cplusplus
}
#endif